home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15428 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: walrus1.walrus.com!warrenj
  2. From: warrenj@walrus.com (Warren Johnson)
  3. Newsgroups: comp.lang.c
  4. Subject: Memory leakage
  5. Date: 17 Apr 1996 16:11:46 GMT
  6. Organization: Intellitech Corporation
  7. Message-ID: <4l3582$1v@alice.walrus.com>
  8. NNTP-Posting-Host: walrus1.walrus.com
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. Suppose I have a function:
  12.  
  13. int give_number() {
  14.    ...
  15.    ...
  16.    ...
  17. }
  18.  
  19. and in main I have a line :
  20.  
  21. if(x>give_number()) { 
  22.   ...
  23.   ... }
  24.  
  25. Now my question is this:  give_number() returns an integer.  Obviously 
  26. the compiler must allocate memory for this integer.  However, we are not 
  27. returning this integer to an integer pointer, therefore this allocated 
  28. memory is floating about in the void somewhere without something pointing 
  29. to it.  Is this memory deallocated when the function is finished running 
  30. it's course or do i have to do this:
  31.  
  32. y = give_number();
  33.  
  34. if(x>y) { blabalh}
  35.  
  36. free(y); // or just let y be deallocated when the function is over with
  37.  
  38. ..........
  39. So any ideas guys? :) 
  40.  
  41. Btw, to all of you who posted in response to my memory allocation 
  42. qeustion: Thank you for your help, it has been quite useful.
  43.  
  44. --
  45. Warren D. Johnson
  46. CEO and Founder
  47. Runtime Computing, Inc.
  48.